<template>
  <div class="report">
    <el-table
      :data="reportData"
      style="width: 100%;margin:0px auto"
      border
      :header-cell-style="{ background: '#f5f5f6', color: '#9EA0A5' }"
    >
      <el-table-column type="index" label="序号" width="80"></el-table-column>
      <el-table-column prop="content" label="告警内容"></el-table-column>
      <el-table-column prop="add_time" label="告警时间"></el-table-column>
      <!-- <el-table-column label="操作">
        <template slot-scope="scoped">
          <el-tooltip class="item" effect="dark" content="该功能尚未上线！" placement="top-start">
            <el-button type="warning" plain>查看此时段运行曲线</el-button>
          </el-tooltip>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeShopChange"
        @current-change="handleCurrentShopChange"
        :current-page="reporForm.pageNumber"
        :page-sizes="[10, 15, 20]"
        :page-size="reporForm.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { warningList } from "../../utils/api";
export default {
  data() {
    return {
      reportData: [],
      reporForm: {
        pageSize: 10,
        pageNumber: 1,
        deviceId: "",
        start_time: "",
        end_time: ""
      },
      total: 0
    };
  },
  methods: {
    // 获取设备列表
    getWarningList() {
      // console.log(this.reporForm);
      this.postRequest(warningList, this.reporForm).then(res => {
        // console.log(res);
        if (res.code == 200) {
          this.reportData = res.data.data;
          this.total = res.data.count;
          window.sessionStorage.removeItem("partTime");
        }
      });
    },
    // 分页
    // 选择每页多少条
    handleSizeShopChange(val) {
      this.reporForm.pageSize = val;
      this.getWarningList();
    },
    // 选择第几页
    handleCurrentShopChange(val) {
      this.reporForm.pageNumber = val;
      this.getWarningList();
    }
  },
  created() {
    let partTime = window.sessionStorage.getItem("partTime");
    const deviceInfo = JSON.parse(
      window.sessionStorage.getItem("facilityData")
    );
    if (window.sessionStorage.getItem("deviceId") != null) {
      this.reporForm.deviceId = window.sessionStorage.getItem("deviceId");
    } else {
      this.reporForm.deviceId = deviceInfo.id;
    }
    this.getWarningList();
    if (partTime != null) {
      let time = JSON.parse(partTime);
      this.start_time = time.start_time;
      this.end_time = time.end_time;
    }
  }
};
</script>
<style lang="less" scoped>
.report {
  padding: 20px;
}
</style>
